package com.moioo.exam;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.hibernate.Query;
import org.hibernate.criterion.Example;

/**
 * A data access object (DAO) providing persistence and search support for
 * TExamParperUserResult entities. Transaction control of the save(), update()
 * and delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see com.moioo.exam.TExamParperUserResult
 * @author MyEclipse Persistence Tools
 */

public class TExamParperUserResultDAO extends BaseHibernateDAO {
	private static final Log log = LogFactory
			.getLog(TExamParperUserResultDAO.class);
	// property constants
	public static final String PARPERID = "parperid";
	public static final String TMID = "tmid";
	public static final String PASSPORT = "passport";
	public static final String ASKID = "askid";
	public static final String SOLUTION = "solution";
	public static final String SCORE = "score";
	public static final String INUSER = "inuser";

	public void save(TExamParperUserResult transientInstance) {
		log.debug("saving TExamParperUserResult instance");
		try {
			getSession().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	public void delete(TExamParperUserResult persistentInstance) {
		log.debug("deleting TExamParperUserResult instance");
		try {
			getSession().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	public TExamParperUserResult findById(java.lang.Integer id) {
		log.debug("getting TExamParperUserResult instance with id: " + id);
		try {
			TExamParperUserResult instance = (TExamParperUserResult) getSession()
					.get("com.moioo.exam.TExamParperUserResult", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	public List findByExample(TExamParperUserResult instance) {
		log.debug("finding TExamParperUserResult instance by example");
		try {
			List results = getSession().createCriteria(
					"com.moioo.exam.TExamParperUserResult").add(
					Example.create(instance)).list();
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	public List findByProperty(String propertyName, Object value) {
		log.debug("finding TExamParperUserResult instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from TExamParperUserResult as model where model."
					+ propertyName + "= ?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setParameter(0, value);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	public List<TExamParperUserResult> get(String passport,int paperid,int tmid){
		log.debug("finding get instance with property: ");
		try {
			String queryString = "from TExamParperUserResult as model where model."
					+ PASSPORT + "= ? and " + PARPERID + " = ? and " + TMID + "=?";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setString(0, passport).setInteger(1, paperid).setInteger(2, tmid);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	public List<TExamParperUserResult> get(String passport,int paperid){
		log.debug("finding get instance with property: ");
		try {
			String queryString = "from TExamParperUserResult as model where model."
					+ PASSPORT + "= ? and " + PARPERID + " = ? ";
			Query queryObject = getSession().createQuery(queryString);
			queryObject.setString(0, passport).setInteger(1, paperid);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}
	public List findByParperid(Object parperid) {
		return findByProperty(PARPERID, parperid);
	}

	public List findByTmid(Object tmid) {
		return findByProperty(TMID, tmid);
	}

	public List findByPassport(Object passport) {
		return findByProperty(PASSPORT, passport);
	}

	public List findByAskid(Object askid) {
		return findByProperty(ASKID, askid);
	}

	public List findBySolution(Object solution) {
		return findByProperty(SOLUTION, solution);
	}

	public List findByScore(Object score) {
		return findByProperty(SCORE, score);
	}

	public List findByInuser(Object inuser) {
		return findByProperty(INUSER, inuser);
	}

	public List findAll() {
		log.debug("finding all TExamParperUserResult instances");
		try {
			String queryString = "from TExamParperUserResult";
			Query queryObject = getSession().createQuery(queryString);
			return queryObject.list();
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	public TExamParperUserResult merge(TExamParperUserResult detachedInstance) {
		log.debug("merging TExamParperUserResult instance");
		try {
			TExamParperUserResult result = (TExamParperUserResult) getSession()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	public void attachDirty(TExamParperUserResult instance) {
		log.debug("attaching dirty TExamParperUserResult instance");
		try {
			getSession().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public void attachClean(TExamParperUserResult instance) {
		log.debug("attaching clean TExamParperUserResult instance");
		try {
			getSession().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}
}